//
//  NumberTest.m
//  MacTestProject
//
//  Created by LiuLichen on 2022/4/12.
//

#import "NumberTest.h"

@implementation NumberTest

- (id) init {
    self = [super init];

    [self testInit];
    [self testOperation];

    return self;
}

- (void) testInit {
    NSNumber* intNum0 = @28;
    NSLog(@"%@", intNum0);
    NSNumber* intNum1 = [NSNumber numberWithInt: 28];
    NSLog(@"%@", intNum1);
    NSNumber* floatNum = [NSNumber numberWithFloat: 3.14f];
    NSLog(@"%@", floatNum);
    NSNumber* doubleNum = [NSNumber numberWithDouble: 24.12];
    NSLog(@"%@", doubleNum);
    NSNumber* boolNum = [NSNumber numberWithBool: TRUE];
    NSLog(@"%@", boolNum);
}

- (void) testOperation {
    {
        NSMutableArray* arr = [NSMutableArray array];
        for (int i = 0; i < 3; i++) {
            [arr addObject: [NSNumber numberWithInt: i]];
        }
        NSLog(@"%@", arr);
    }
    {
        NSNumber* num = [NSNumber numberWithDouble: 3.1415926];
        double d = [num doubleValue];
        int i = [num intValue];
        NSString* nss = [num stringValue];
        NSLog(@"to double: %lf", d);
        NSLog(@"to int: %d", i);
        NSLog(@"to string: %@", nss);
    }
}

@end
